package com.beetlestech.nfe.main.biz.com.impl;

import com.beetlestech.nfe.fw.core.biz.AbstractDBLogic;
import com.beetlestech.nfe.fw.core.util.StringUtil;
import com.beetlestech.nfe.main.biz.com.HbTeacher;
import com.beetlestech.nfe.main.biz.constant.CommonConstant;
import com.beetlestech.nfe.main.biz.constant.CtgCodeConstant;
import com.beetlestech.nfe.main.biz.constant.HbMessageCode;
import com.beetlestech.nfe.main.db.constant.SQLConstant;
import com.beetlestech.nfe.main.db.tbl.HomeworkhistoryDTO;
import com.beetlestech.nfe.main.db.tbl.MstfileDTO;
import com.beetlestech.nfe.main.db.tbl.MstusrDTO;

public class HbTeacherImpl extends AbstractDBLogic implements HbTeacher, CtgCodeConstant, HbMessageCode, CommonConstant, SQLConstant  {
	//标记为已处理
	@Override
	public void UpdateHistory(String actionType,String teacherSql){
		if(actionType.equals("many")){
			String[] dbSqlArray=teacherSql.split(",");
			for (int i = 0; i < dbSqlArray.length; i++) {
				if(StringUtil.isEmpty(dbSqlArray[i])){
					break;
				}
				HomeworkhistoryDTO home = new HomeworkhistoryDTO();
				home.sethistoryid(Integer.parseInt(dbSqlArray[i]));
				home = queryDAO.queryForObject(HomeworkhistoryDTO.EQUAL_SEARCH, home);
				//标记为已处理
				home.setstate(1);
				updateDAO.updateOne(HomeworkhistoryDTO.UPDATE, home, M10190WS);
			}
		}
	}
	//删除教师
	@Override
	public void deleteTeacher(String actionType,String teacherSql,Integer usr_id) {
		if(actionType.equals("single")){
			MstusrDTO mstusrDTO =new MstusrDTO();
			if(usr_id==null){
				return ;
			}
			mstusrDTO.setusrid(usr_id);
			mstusrDTO.settype(2);
			updateDAO.updateOne(MstusrDTO.DELETE, mstusrDTO, M10190WS);
			
		}else if(actionType.equals("many")){
			String[] dbSqlArray=teacherSql.split(",");
			for (int i = 0; i < dbSqlArray.length; i++) {
				if(StringUtil.isEmpty(dbSqlArray[i])){
					break;
				}
				MstusrDTO mstusrDTO =new MstusrDTO();
				mstusrDTO.setusrid(Integer.parseInt(dbSqlArray[i]));
				mstusrDTO.settype(2);
				updateDAO.updateOne(MstusrDTO.DELETE, mstusrDTO, M10190WS);
				
			}
		}
	}
	//根据historyId返回下载地址
	@Override
	public String DownloadTeacherHomework(Integer historyId){
		
			HomeworkhistoryDTO home = new HomeworkhistoryDTO();
			home.sethistoryid(historyId);
			home = queryDAO.queryForObject(HomeworkhistoryDTO.EQUAL_SEARCH, home);
			MstfileDTO mstfileDTO = new MstfileDTO();
			mstfileDTO.setfileid(home.getfileid());
			mstfileDTO = queryDAO.queryForObject(MstfileDTO.EQUAL_SEARCH, mstfileDTO);
			String path=mstfileDTO.getpath();
			return path;
		
	}
}
